/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.inse6260.atms.view;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.Box;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JTextArea;
import javax.swing.BorderFactory;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 *
 * @author dimitri.tiago
 */
public class Receipt
{
    public Receipt(String receiptText, JFrame parent)
    {
        // create the dialog.
        final JDialog dialog = new JDialog(parent,"TRANSACTION RECEIPT");

        // populate dialog 
        JTextArea textArea = new JTextArea(100, 20);
        textArea.setEnabled(false);
        textArea.setDisabledTextColor(Color.BLACK);
        textArea.setText(receiptText);

        JButton closeButton = new JButton("Close");
        closeButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                dialog.setVisible(false);
                dialog.dispose();
            }
        });

        JPanel closePanel = new JPanel();
        closePanel.setLayout(new BoxLayout(closePanel, BoxLayout.LINE_AXIS));
        closePanel.add(Box.createHorizontalGlue());
        closePanel.add(closeButton);
        closePanel.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));

        JPanel contentPane = new JPanel(new BorderLayout());
        contentPane.add(textArea, BorderLayout.CENTER);
        contentPane.add(closePanel, BorderLayout.PAGE_END);
        contentPane.setOpaque(true);
        dialog.setContentPane(contentPane);

        // display frame
        dialog.setSize(350, 130);
        dialog.setLocationRelativeTo(parent);
        dialog.setVisible(true);
    }
}
